//
//  PublicButton.m
//  AAIM
//
//  Created by awh on 2019/11/29.
//  Copyright © 2019年 AAIM. All rights reserved.
//

#import "PublicButton.h"

@implementation PublicButton
-(instancetype)initWithFrame:(CGRect)frame withButtonType:(NSString*)type
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createButtonWithType:type];
    }
    return self;
}
-(void)createButtonWithType:(NSString*)type
{
    if ([type isEqualToString:@"FriendInfoVCButton"]) {
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(0,self.height/2-9,180*SCALAE, 18) Font:15 titleColor:KHEXCOLOR(@"#262B2F") textAlignment:0];
        [self addSubview:self.titleLbl];
        
        _remarkLbl=[[UILabel alloc]init];
        _remarkLbl=[self CreateLabelWithFrame:CGRectMake(0,self.height/2-9,180*SCALAE, 18) Font:15 titleColor:KHEXCOLOR(@"#262B2F") textAlignment:2];
        [self addSubview:self.remarkLbl];
        
        _iconImage=[[UIImageView alloc]initWithFrame:CGRectMake(self.width-15, self.height/2-9, 7, 15)];
        _iconImage.image=[UIImage imageNamed:@"我的-返回键头"];
//        _iconImage.layer.masksToBounds=YES;
//        _iconImage.layer.cornerRadius=20;
        [self addSubview:self.iconImage];
        
        _lineV=[[UIView alloc]initWithFrame:CGRectMake(_titleLbl.x, self.height-0.5, self.width-_titleLbl.x*2, 0.5)];
        _lineV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
        [self addSubview:self.lineV];
    }else if([type isEqualToString:@"friendChatSetButton"])
    {
        _iconImage=[[UIImageView alloc]initWithFrame:CGRectMake(self.width/2-25, 1, 50, 50)];
        _iconImage.layer.masksToBounds=YES;
        _iconImage.layer.cornerRadius=25;
        [self addSubview:self.iconImage];
        
        
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(0,_iconImage.bottom+10,self.width, 15) Font:12 titleColor:KHEXCOLOR(kGrayColor_66) textAlignment:1];
        [self addSubview:self.titleLbl];
    
    }else if ([type isEqualToString:@"friendChatSetCellButton"])
    {
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(15,self.height/2-15,160, 30) Font:15 titleColor:KHEXCOLOR(AllBackColor_titleColor) textAlignment:0];
        [self addSubview:self.titleLbl];
        
     
        _swicthButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _swicthButton.frame=CGRectMake(self.width-60, 0, 40, self.height);
        [_swicthButton setImage:[UIImage imageNamed:@"关闭按钮"] forState:UIControlStateNormal];
        [_swicthButton setImage:[UIImage imageNamed:@"开按钮"] forState:UIControlStateSelected];
        [self addSubview:self.swicthButton];
        
        _lineV=[[UIView alloc]initWithFrame:CGRectMake(0, self.height-1*SCALAE, self.width, 1*SCALAE)];
        _lineV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
        [self addSubview:self.lineV];
        
        
    }else if ([type isEqualToString:@"groupSetbutton"])
    {
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(15,self.height/2-15,160, 30) Font:14 titleColor:KHEXCOLOR(AllBackColor_titleColor) textAlignment:0];
        [self addSubview:self.titleLbl];
        
        
        _swicthButton=[UIButton buttonWithType:UIButtonTypeCustom];
        _swicthButton.frame=CGRectMake(self.width-55, 0, 40, self.height);
        [_swicthButton setImage:[UIImage imageNamed:@"关闭按钮"] forState:UIControlStateNormal];
        [_swicthButton setImage:[UIImage imageNamed:@"开按钮"] forState:UIControlStateSelected];
        [self addSubview:self.swicthButton];
        
        
        _rigthImage=[[UIImageView alloc]initWithFrame:CGRectMake(self.width-30, self.height/2-7.5, 15, 15)];
        _rigthImage.image=[UIImage imageNamed:@"群设置-返回键"];
        _rigthImage.contentMode=UIViewContentModeScaleAspectFit;
        [self addSubview:self.rigthImage];

        //群公告用
        _remarkLbl=[self CreateLabelWithFrame:CGRectMake(_rigthImage.x-185,self.height/2-7.5,180, 15) Font:13 titleColor:KHEXCOLOR(@"#AFAFAF") textAlignment:0];
        _remarkLbl.hidden=NO;
        [self addSubview:self.remarkLbl];
        
        _lineV=[[UIView alloc]initWithFrame:CGRectMake(15, self.height-1*SCALAE, self.width-30, 1*SCALAE)];
        _lineV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
        [self addSubview:self.lineV];
        
    }else if ([type isEqualToString:@"ContactorsVCButton"])
    {
        _iconImage=[[UIImageView alloc]initWithFrame:CGRectMake(15, self.height/2-17.5, 35, 35)];
        _iconImage.layer.masksToBounds=YES;
        _iconImage.layer.cornerRadius=17.5;
        _iconImage.image=[UIImage imageNamed:@"addfriend"];
        [self addSubview:self.iconImage];
        
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(_iconImage.right+10,self.height/2-7.5,120, 15) Font:15 titleColor:KHEXCOLOR(kBlackColor) textAlignment:0];
        _titleLbl.text=@"新的好友";
        [self addSubview:self.titleLbl];
        
        _rigthImage=[[UIImageView alloc]initWithFrame:CGRectMake(self.width-30, self.height/2-7.5, 15, 15)];
        _rigthImage.image=[UIImage imageNamed:@"群设置-返回键"];
        _rigthImage.contentMode=UIViewContentModeScaleAspectFit;
        [self addSubview:self.rigthImage];
        
        _remarkLbl=[self CreateLabelWithFrame:CGRectMake(_rigthImage.x-26, self.height/2-8, 16, 16) Font:11.5 titleColor:[UIColor whiteColor] textAlignment:1];
        _remarkLbl.layer.masksToBounds=YES;
        _remarkLbl.layer.cornerRadius=8;
        _remarkLbl.backgroundColor=KHEXCOLOR(@"#E94634");
        [self addSubview:self.remarkLbl];
    }else if ([type isEqualToString:@"ContactorsPublicButton"]){
        _iconImage=[[UIImageView alloc]initWithFrame:CGRectMake(15, self.height/2-17.5, 35, 35)];
        _iconImage.layer.masksToBounds=YES;
        _iconImage.layer.cornerRadius=17.5;
        _iconImage.image=[UIImage imageNamed:@"联系人-公众号"];
        [self addSubview:self.iconImage];
        
        _titleLbl=[self CreateLabelWithFrame:CGRectMake(_iconImage.right+10,self.height/2-7.5,120, 15) Font:15 titleColor:KHEXCOLOR(kBlackColor) textAlignment:0];
        _titleLbl.text=@"公众号";
        [self addSubview:self.titleLbl];
        
        _rigthImage=[[UIImageView alloc]initWithFrame:CGRectMake(self.width-30, self.height/2-7.5, 15, 15)];
        _rigthImage.image=[UIImage imageNamed:@"群设置-返回键"];
        _rigthImage.contentMode=UIViewContentModeScaleAspectFit;
        [self addSubview:self.rigthImage];
        
        _remarkLbl=[self CreateLabelWithFrame:CGRectMake(_rigthImage.x-26, self.height/2-8, 16, 16) Font:11.5 titleColor:[UIColor whiteColor] textAlignment:1];
        _remarkLbl.layer.masksToBounds=YES;
        _remarkLbl.layer.cornerRadius=8;
        _remarkLbl.backgroundColor=KHEXCOLOR(@"#E94634");
//        [self addSubview:self.remarkLbl];
    }
}
-(UILabel*)CreateLabelWithFrame:(CGRect)Frame Font:(CGFloat)font titleColor:(UIColor*)titleColor textAlignment:(NSInteger)textAlignment
{
    UILabel * lbl=[[UILabel alloc]initWithFrame:Frame];
    lbl.font=[UIFont systemFontOfSize:font];
    lbl.textColor=titleColor;
    lbl.textAlignment=textAlignment;
    return lbl;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
